package scau.erps.service.impl;

import java.util.List;

import org.nutz.dao.Cnd;
import org.nutz.dao.util.cri.SqlExpressionGroup;
import org.nutz.service.IdEntityService;

import scau.erps.entity.Balancesheet;
import scau.erps.service.BalancesheetService;

/**
 * 报表——资产负债表实现类
 * @author FYJ
 *
 */
public class BalancesheetServiceImpl extends IdEntityService<Balancesheet> implements BalancesheetService{

	@Override
	public List<Balancesheet> getBalancesheetOfThisYear(int teamid, String year) {
		SqlExpressionGroup e1 = null;
		SqlExpressionGroup e2 = null;
		String thisYear = "Y"+year.charAt(1);
		if(teamid != 0){
			e1 = Cnd.exps("teamid", "=", teamid);			
		}
		if(year != null){
			e2 = Cnd.exps("year", "=", thisYear);
		}
		return this.query(Cnd.where(e1).and(e2), null);
	}

	@Override
	public List<Balancesheet> getBalancesheetOfLastYear(int teamid, String year) {
		SqlExpressionGroup e1 = null;
		SqlExpressionGroup e2 = null;
		
		if(teamid != 0){
			e1 = Cnd.exps("teamid", "=", teamid);			
		}
		if(year != null){
			char y;
			if(((char)(year.charAt(1))=='0'))
				 y='8';
			else{
			 y = (char) (year.charAt(1)-1);
			}
			String oldYear = "Y"+y;
			e2 = Cnd.exps("year", "=", oldYear);
			
		}
		return this.query(Cnd.where(e1).and(e2), null);
	}
	@Override
	public List<Balancesheet> getBalancesheetByTeamid(int teamid) {
		SqlExpressionGroup e1 = null;
		if(teamid != 0){
			e1 = Cnd.exps("teamid", "=", teamid);			
		}
		return this.query(Cnd.where(e1), null);
	}
	@Override
	public void updateBalancesheet(Balancesheet balancesheet) {
		this.dao().update(balancesheet);
		
	}



}
